<template>
  <div class="elm-edit">
    <elm-page-bb>
      <el-form ref="model" :model="model" size="small" label-width="120px">
        <elm-row>
          <el-form-item label="进货批次" prop="name" :rules="[{ required: true, message: '必须填写'}]">
            <el-input v-model="model.name"></el-input>
          </el-form-item>
          <el-form-item label="货物名称" prop="dict">
            <elm-select style="width: 100%" v-model="model.dict" url="/business/jxc/goods/dict/GetData"></elm-select>
          </el-form-item>
        </elm-row>
        <elm-row>
          <el-form-item label="规格/型号" prop="specification">
            <el-input v-model="model.specification"></el-input>
          </el-form-item>
          <el-form-item label="数量" prop="quantity" :rules="[{trigger: 'blur' ,validator: validateNumber}]">
            <el-input v-model.number="model.quantity"></el-input>
          </el-form-item>
        </elm-row>
        <elm-row>
          <el-form-item label="进货价" prop="price" :rules="[{trigger: 'blur' ,validator: validateNumber}]">
            <el-input v-model.number="model.price"></el-input>
          </el-form-item>
          <el-form-item label="税率" prop="tex" :rules="[{trigger: 'blur' ,validator: validateNumber}]">
            <el-input v-model.number="model.tex">
              <template slot="append">
                <div style="width: 25px;text-align: center;">{{"%"}}</div>
              </template>
            </el-input>
          </el-form-item>
        </elm-row>
        <elm-row>
          <el-form-item label="生产日期" prop="made_date">
            <el-date-picker v-model="model.made_date"  type="date" value-format="yyyy-MM-dd" style="width: 100%"></el-date-picker>
          </el-form-item>
          <el-form-item label="有效期至" prop="shelf_life">
            <el-date-picker v-model="model.shelf_life"  type="date" value-format="yyyy-MM-dd" style="width: 100%"></el-date-picker>
          </el-form-item>
        </elm-row>
        <el-form-item label="厂家" prop="manufacturer">
          <el-input v-model="model.manufacturer" type="textarea" :rows="2"></el-input>
        </el-form-item>
        <el-form-item label="备注" prop="remarks">
          <el-input v-model="model.remarks" type="textarea" :rows="2"></el-input>
        </el-form-item>
      </el-form>
      <template #bottom>
        <el-button type="success" size="small" @click="submit">立即保存</el-button>
        <el-button size="small" @click="close">取消</el-button>
      </template>
    </elm-page-bb>
  </div>
</template>

<script>
export default {
  extends: elmVueBase,
  data() {
    return {
      model: {id: elm.newGuid(),create_time:new Date().toLocaleString('sv-SE').slice(0, 19).replace("T", " ")},
    }
  },
  async created() {
  },
  destroyed() {
    this.request.callVue.tablebinding();
  },
  methods: {
    async submit() {
      this.model.last_update_time=new Date().toLocaleString('sv-SE').slice(0, 19).replace("T", " ");
      await this.$refs["model"].validate();
      var res = await elm.post('/business/jxc/goods/Upsert', this.model);
      if (res == true) {
        this.v('保存成功。')
        this.close();
        this.request.callVue.tablebinding();
      }
      else {
        this.error('保存失败，请稍后尝试。');
      }
    },
  }
}
</script>
